{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "897068e9",
   "metadata": {},
   "source": [
    "# Star shaped qubit\n",
    "\n",
    "We'll be creating a 2D design and adding a star shaped qubit QComponent.\n",
    "\n",
    "\n",
    "There's a central star shaped component. This component is essentially a circle with trpezoids subtracted from it. A T-junction qubit is attached to this central shape. Then there are four coupling resonators and one readout resonator present in the default setting. The shape of the central component and the number coupling resonators are customizable. Let's try out a few diferent ways to create and render this component."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "4920e2a9",
   "metadata": {},
   "outputs": [],
   "source": [
    "# So, let us dive right in. For convenience, let's begin by enabling\n",
    "# automatic reloading of modules when they change.\n",
    "%load_ext autoreload\n",
    "%autoreload 2"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "d55665b3",
   "metadata": {},
   "source": [
    "Next, we import the relevant modules. You can add new modules as and when needed. "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "bright-latex",
   "metadata": {},
   "outputs": [],
   "source": [
    "import qiskit_metal as metal\n",
    "import numpy as np\n",
    "from math import *\n",
    "from qiskit_metal import designs, draw, Dict\n",
    "from qiskit_metal.qlibrary.core import BaseQubit, QComponent"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "a9e25057",
   "metadata": {},
   "source": [
    "Next we import the GUI"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "endangered-saying",
   "metadata": {},
   "outputs": [],
   "source": [
    "from qiskit_metal import MetalGUI"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "5bf14a49",
   "metadata": {},
   "source": [
    "A QDesign class must be instantiated each time a new quantum circuit design is created. The design class `DesignPlanar` is best for 2D circuit designs."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "civil-characteristic",
   "metadata": {},
   "outputs": [],
   "source": [
    "design = designs.DesignPlanar()\n",
    "gui = MetalGUI(design)\n",
    "gui.rebuild() "
   ]
  },
  {
   "cell_type": "markdown",
   "id": "99f5beef",
   "metadata": {},
   "source": [
    "# A Star Qubit\n",
    "\n",
    "You can create a ready-made star qubit from the QComponent Library, qiskit_metal.qlibrary.qubits. star_qubit.py is the file containing our qubit so StarQubit is the module we import. \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "913c82b8",
   "metadata": {},
   "outputs": [],
   "source": [
    "from qiskit_metal.qlibrary.qubits.star_qubit import StarQubit"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "b47cbef4",
   "metadata": {},
   "outputs": [],
   "source": [
    "# The following default_options can be overridden by user.\n",
    "StarQubit.get_template_options(design)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "b01be30b",
   "metadata": {},
   "outputs": [],
   "source": [
    "# To force overwrite a QComponent with an existing name.  \n",
    "# This is useful when re-running cells in a notebook. \n",
    "design.overwrite_enabled = True"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "96a19309",
   "metadata": {},
   "source": [
    "Let us place the qubit at (x,y) =(5,5), and change the default rotation values. As this design is meant to have up to 5 contacts including one readout and up to 4 coupling resonators, these angles should be 72 degrees apart. However, the number of connectors may be changed to any value between 0 and 4."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "a3926220",
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "qubit_options = dict(\n",
    "    pos_x = '7um',\n",
    "    pos_y = '7um',  \n",
    "    number_of_connectors = 4 # Change the number of connectors\n",
    ")\n",
    "\n",
    "# Create a new Concentric Transmon object with name 'Q1' \n",
    "q1 = StarQubit(design, 'Star', options=qubit_options)\n",
    "\n",
    "gui.rebuild()  # rebuild the design and plot \n",
    "gui.autoscale() #resize GUI to see QComponent\n",
    "gui.zoom_on_components(['Star']) #Can also gui.zoom_on_components([q1.name])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "rotary-charity",
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "#Let's see what the Q1 object looks like\n",
    "\n",
    "q1 #print Q1 information"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "bca963d5",
   "metadata": {},
   "outputs": [],
   "source": [
    "#Save screenshot as a .png formatted file.\n",
    "gui.screenshot()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "fe6d25d6",
   "metadata": {},
   "outputs": [],
   "source": [
    "# Screenshot the canvas only as a .png formatted file.\n",
    "gui.figure.savefig('shot.png')\n",
    "\n",
    "from IPython.display import Image, display\n",
    "_disp_ops = dict(width=500)\n",
    "display(Image('shot.png', **_disp_ops))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "9a8beab7",
   "metadata": {},
   "source": [
    "# Closing the Qiskit Metal GUI"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "6b79072d",
   "metadata": {},
   "outputs": [],
   "source": [
    "# gui.main_window.close()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "44d1545c",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
